﻿///////////////////////////////////////////////////////////////
// This is generated code. 
//////////////////////////////////////////////////////////////
// Code is generated using LLBLGen Pro version: 3.1
// Code is generated on: Thursday, June 23, 2011 1:28:25 PM
// Code is generated using templates: SD.TemplateBindings.SharedTemplates.NET20
// Templates vendor: Solutions Design.
// Templates version: 
//////////////////////////////////////////////////////////////
using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Collections;
#if !CF
using System.Runtime.Serialization;
#endif
using System.Data;
using System.Xml.Serialization;
using MyHealthOnline.Dal.Generated;
using MyHealthOnline.Dal.Generated.FactoryClasses;
using MyHealthOnline.Dal.Generated.DaoClasses;
using MyHealthOnline.Dal.Generated.RelationClasses;
using MyHealthOnline.Dal.Generated.HelperClasses;
using MyHealthOnline.Dal.Generated.CollectionClasses;

using SD.LLBLGen.Pro.ORMSupportClasses;

namespace MyHealthOnline.Dal.Generated.EntityClasses
{
	
	// __LLBLGENPRO_USER_CODE_REGION_START AdditionalNamespaces
	// __LLBLGENPRO_USER_CODE_REGION_END
	

	/// <summary>Entity class which represents the entity 'Consult'. <br/><br/>
	/// 
	/// </summary>
	[Serializable]
	public partial class ConsultEntity : CommonEntityBase
		// __LLBLGENPRO_USER_CODE_REGION_START AdditionalInterfaces
		// __LLBLGENPRO_USER_CODE_REGION_END
			
	{
		#region Class Member Declarations
		private MyHealthOnline.Dal.Generated.CollectionClasses.AppProposalCollection	_appProposal;
		private bool	_alwaysFetchAppProposal, _alreadyFetchedAppProposal;
		private MyHealthOnline.Dal.Generated.CollectionClasses.ConsultQuestionCollection	_consultQuestion;
		private bool	_alwaysFetchConsultQuestion, _alreadyFetchedConsultQuestion;
		private MyHealthOnline.Dal.Generated.CollectionClasses.MessageCollection	_msgEnvelopes;
		private bool	_alwaysFetchMsgEnvelopes, _alreadyFetchedMsgEnvelopes;
		private PatientEntity _pacient;
		private bool	_alwaysFetchPacient, _alreadyFetchedPacient, _pacientReturnsNewIfNotFound;
		private SpecialistEntity _specialist;
		private bool	_alwaysFetchSpecialist, _alreadyFetchedSpecialist, _specialistReturnsNewIfNotFound;

		// __LLBLGENPRO_USER_CODE_REGION_START PrivateMembers
		// __LLBLGENPRO_USER_CODE_REGION_END
		
		#endregion

		#region Statics
		private static Dictionary<string, string>	_customProperties;
		private static Dictionary<string, Dictionary<string, string>>	_fieldsCustomProperties;

		/// <summary>All names of fields mapped onto a relation. Usable for in-memory filtering</summary>
		public static partial class MemberNames
		{
			/// <summary>Member name Pacient</summary>
			public static readonly string Pacient = "Pacient";
			/// <summary>Member name Specialist</summary>
			public static readonly string Specialist = "Specialist";
			/// <summary>Member name AppProposal</summary>
			public static readonly string AppProposal = "AppProposal";
			/// <summary>Member name ConsultQuestion</summary>
			public static readonly string ConsultQuestion = "ConsultQuestion";
			/// <summary>Member name MsgEnvelopes</summary>
			public static readonly string MsgEnvelopes = "MsgEnvelopes";
		}
		#endregion
		
		/// <summary>Static CTor for setting up custom property hashtables. Is executed before the first instance of this entity class or derived classes is constructed. </summary>
		static ConsultEntity()
		{
			SetupCustomPropertyHashtables();
		}

		/// <summary>CTor</summary>
		public ConsultEntity() : base()
		{
			InitClassEmpty(null);
		}
		
		/// <summary>CTor</summary>
		/// <param name="id">PK value for Consult which data should be fetched into this Consult object</param>
		public ConsultEntity(System.Int32 id)
		{
			InitClassFetch(id, null, null);
		}

		/// <summary>CTor</summary>
		/// <param name="id">PK value for Consult which data should be fetched into this Consult object</param>
		/// <param name="prefetchPathToUse">the PrefetchPath which defines the graph of objects to fetch as well</param>
		public ConsultEntity(System.Int32 id, IPrefetchPath prefetchPathToUse)
		{
			InitClassFetch(id, null, prefetchPathToUse);
		}

		/// <summary>CTor</summary>
		/// <param name="id">PK value for Consult which data should be fetched into this Consult object</param>
		/// <param name="validator">The custom validator object for this ConsultEntity</param>
		public ConsultEntity(System.Int32 id, IValidator validator)
		{
			InitClassFetch(id, validator, null);
		}

		/// <summary>Private CTor for deserialization</summary>
		/// <param name="info"></param>
		/// <param name="context"></param>
		protected ConsultEntity(SerializationInfo info, StreamingContext context) : base(info, context)
		{
			_appProposal = (MyHealthOnline.Dal.Generated.CollectionClasses.AppProposalCollection)info.GetValue("_appProposal", typeof(MyHealthOnline.Dal.Generated.CollectionClasses.AppProposalCollection));
			_alwaysFetchAppProposal = info.GetBoolean("_alwaysFetchAppProposal");
			_alreadyFetchedAppProposal = info.GetBoolean("_alreadyFetchedAppProposal");

			_consultQuestion = (MyHealthOnline.Dal.Generated.CollectionClasses.ConsultQuestionCollection)info.GetValue("_consultQuestion", typeof(MyHealthOnline.Dal.Generated.CollectionClasses.ConsultQuestionCollection));
			_alwaysFetchConsultQuestion = info.GetBoolean("_alwaysFetchConsultQuestion");
			_alreadyFetchedConsultQuestion = info.GetBoolean("_alreadyFetchedConsultQuestion");

			_msgEnvelopes = (MyHealthOnline.Dal.Generated.CollectionClasses.MessageCollection)info.GetValue("_msgEnvelopes", typeof(MyHealthOnline.Dal.Generated.CollectionClasses.MessageCollection));
			_alwaysFetchMsgEnvelopes = info.GetBoolean("_alwaysFetchMsgEnvelopes");
			_alreadyFetchedMsgEnvelopes = info.GetBoolean("_alreadyFetchedMsgEnvelopes");
			_pacient = (PatientEntity)info.GetValue("_pacient", typeof(PatientEntity));
			if(_pacient!=null)
			{
				_pacient.AfterSave+=new EventHandler(OnEntityAfterSave);
			}
			_pacientReturnsNewIfNotFound = info.GetBoolean("_pacientReturnsNewIfNotFound");
			_alwaysFetchPacient = info.GetBoolean("_alwaysFetchPacient");
			_alreadyFetchedPacient = info.GetBoolean("_alreadyFetchedPacient");

			_specialist = (SpecialistEntity)info.GetValue("_specialist", typeof(SpecialistEntity));
			if(_specialist!=null)
			{
				_specialist.AfterSave+=new EventHandler(OnEntityAfterSave);
			}
			_specialistReturnsNewIfNotFound = info.GetBoolean("_specialistReturnsNewIfNotFound");
			_alwaysFetchSpecialist = info.GetBoolean("_alwaysFetchSpecialist");
			_alreadyFetchedSpecialist = info.GetBoolean("_alreadyFetchedSpecialist");
			this.FixupDeserialization(FieldInfoProviderSingleton.GetInstance(), PersistenceInfoProviderSingleton.GetInstance());
			// __LLBLGENPRO_USER_CODE_REGION_START DeserializationConstructor
			// __LLBLGENPRO_USER_CODE_REGION_END
			
		}
		
		
		/// <summary>Performs the desync setup when an FK field has been changed. The entity referenced based on the FK field will be dereferenced and sync info will be removed.</summary>
		/// <param name="fieldIndex">The fieldindex.</param>
		protected override void PerformDesyncSetupFKFieldChange(int fieldIndex)
		{
			switch((ConsultFieldIndex)fieldIndex)
			{
				case ConsultFieldIndex.PatientId:
					DesetupSyncPacient(true, false);
					_alreadyFetchedPacient = false;
					break;
				case ConsultFieldIndex.SpecialistId:
					DesetupSyncSpecialist(true, false);
					_alreadyFetchedSpecialist = false;
					break;
				default:
					base.PerformDesyncSetupFKFieldChange(fieldIndex);
					break;
			}
		}

		/// <summary> Will perform post-ReadXml actions</summary>
		protected override void PostReadXmlFixups()
		{
			_alreadyFetchedAppProposal = (_appProposal.Count > 0);
			_alreadyFetchedConsultQuestion = (_consultQuestion.Count > 0);
			_alreadyFetchedMsgEnvelopes = (_msgEnvelopes.Count > 0);
			_alreadyFetchedPacient = (_pacient != null);
			_alreadyFetchedSpecialist = (_specialist != null);
		}
				
		/// <summary>Gets the relation objects which represent the relation the fieldName specified is mapped on. </summary>
		/// <param name="fieldName">Name of the field mapped onto the relation of which the relation objects have to be obtained.</param>
		/// <returns>RelationCollection with relation object(s) which represent the relation the field is maped on</returns>
		protected override RelationCollection GetRelationsForFieldOfType(string fieldName)
		{
			return GetRelationsForField(fieldName);
		}

		/// <summary>Gets the relation objects which represent the relation the fieldName specified is mapped on. </summary>
		/// <param name="fieldName">Name of the field mapped onto the relation of which the relation objects have to be obtained.</param>
		/// <returns>RelationCollection with relation object(s) which represent the relation the field is maped on</returns>
		internal static RelationCollection GetRelationsForField(string fieldName)
		{
			RelationCollection toReturn = new RelationCollection();
			switch(fieldName)
			{
				case "Pacient":
					toReturn.Add(Relations.PatientEntityUsingPatientId);
					break;
				case "Specialist":
					toReturn.Add(Relations.SpecialistEntityUsingSpecialistId);
					break;
				case "AppProposal":
					toReturn.Add(Relations.AppProposalEntityUsingConsultId);
					break;
				case "ConsultQuestion":
					toReturn.Add(Relations.ConsultQuestionEntityUsingConsultId);
					break;
				case "MsgEnvelopes":
					toReturn.Add(Relations.MessageEntityUsingConsultId);
					break;
				default:
					break;				
			}
			return toReturn;
		}



		/// <summary> ISerializable member. Does custom serialization so event handlers do not get serialized.</summary>
		/// <param name="info"></param>
		/// <param name="context"></param>
		[EditorBrowsable(EditorBrowsableState.Never)]
		protected override void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			info.AddValue("_appProposal", (!this.MarkedForDeletion?_appProposal:null));
			info.AddValue("_alwaysFetchAppProposal", _alwaysFetchAppProposal);
			info.AddValue("_alreadyFetchedAppProposal", _alreadyFetchedAppProposal);
			info.AddValue("_consultQuestion", (!this.MarkedForDeletion?_consultQuestion:null));
			info.AddValue("_alwaysFetchConsultQuestion", _alwaysFetchConsultQuestion);
			info.AddValue("_alreadyFetchedConsultQuestion", _alreadyFetchedConsultQuestion);
			info.AddValue("_msgEnvelopes", (!this.MarkedForDeletion?_msgEnvelopes:null));
			info.AddValue("_alwaysFetchMsgEnvelopes", _alwaysFetchMsgEnvelopes);
			info.AddValue("_alreadyFetchedMsgEnvelopes", _alreadyFetchedMsgEnvelopes);
			info.AddValue("_pacient", (!this.MarkedForDeletion?_pacient:null));
			info.AddValue("_pacientReturnsNewIfNotFound", _pacientReturnsNewIfNotFound);
			info.AddValue("_alwaysFetchPacient", _alwaysFetchPacient);
			info.AddValue("_alreadyFetchedPacient", _alreadyFetchedPacient);
			info.AddValue("_specialist", (!this.MarkedForDeletion?_specialist:null));
			info.AddValue("_specialistReturnsNewIfNotFound", _specialistReturnsNewIfNotFound);
			info.AddValue("_alwaysFetchSpecialist", _alwaysFetchSpecialist);
			info.AddValue("_alreadyFetchedSpecialist", _alreadyFetchedSpecialist);

			// __LLBLGENPRO_USER_CODE_REGION_START GetObjectInfo
			// __LLBLGENPRO_USER_CODE_REGION_END
			
			base.GetObjectData(info, context);
		}
		
		/// <summary> Sets the related entity property to the entity specified. If the property is a collection, it will add the entity specified to that collection.</summary>
		/// <param name="propertyName">Name of the property.</param>
		/// <param name="entity">Entity to set as an related entity</param>
		/// <remarks>Used by prefetch path logic.</remarks>
		[EditorBrowsable(EditorBrowsableState.Never)]
		protected override void SetRelatedEntityProperty(string propertyName, IEntity entity)
		{
			switch(propertyName)
			{
				case "Pacient":
					_alreadyFetchedPacient = true;
					this.Pacient = (PatientEntity)entity;
					break;
				case "Specialist":
					_alreadyFetchedSpecialist = true;
					this.Specialist = (SpecialistEntity)entity;
					break;
				case "AppProposal":
					_alreadyFetchedAppProposal = true;
					if(entity!=null)
					{
						this.AppProposal.Add((AppProposalEntity)entity);
					}
					break;
				case "ConsultQuestion":
					_alreadyFetchedConsultQuestion = true;
					if(entity!=null)
					{
						this.ConsultQuestion.Add((ConsultQuestionEntity)entity);
					}
					break;
				case "MsgEnvelopes":
					_alreadyFetchedMsgEnvelopes = true;
					if(entity!=null)
					{
						this.MsgEnvelopes.Add((MessageEntity)entity);
					}
					break;
				default:
					this.OnSetRelatedEntityProperty(propertyName, entity);
					break;
			}
		}

		/// <summary> Sets the internal parameter related to the fieldname passed to the instance relatedEntity. </summary>
		/// <param name="relatedEntity">Instance to set as the related entity of type entityType</param>
		/// <param name="fieldName">Name of field mapped onto the relation which resolves in the instance relatedEntity</param>
		[EditorBrowsable(EditorBrowsableState.Never)]
		protected override void SetRelatedEntity(IEntity relatedEntity, string fieldName)
		{
			switch(fieldName)
			{
				case "Pacient":
					SetupSyncPacient(relatedEntity);
					break;
				case "Specialist":
					SetupSyncSpecialist(relatedEntity);
					break;
				case "AppProposal":
					_appProposal.Add((AppProposalEntity)relatedEntity);
					break;
				case "ConsultQuestion":
					_consultQuestion.Add((ConsultQuestionEntity)relatedEntity);
					break;
				case "MsgEnvelopes":
					_msgEnvelopes.Add((MessageEntity)relatedEntity);
					break;
				default:
					break;
			}
		}
		
		/// <summary> Unsets the internal parameter related to the fieldname passed to the instance relatedEntity. Reverses the actions taken by SetRelatedEntity() </summary>
		/// <param name="relatedEntity">Instance to unset as the related entity of type entityType</param>
		/// <param name="fieldName">Name of field mapped onto the relation which resolves in the instance relatedEntity</param>
		/// <param name="signalRelatedEntityManyToOne">if set to true it will notify the manytoone side, if applicable.</param>
		[EditorBrowsable(EditorBrowsableState.Never)]
		protected override void UnsetRelatedEntity(IEntity relatedEntity, string fieldName, bool signalRelatedEntityManyToOne)
		{
			switch(fieldName)
			{
				case "Pacient":
					DesetupSyncPacient(false, true);
					break;
				case "Specialist":
					DesetupSyncSpecialist(false, true);
					break;
				case "AppProposal":
					this.PerformRelatedEntityRemoval(_appProposal, relatedEntity, signalRelatedEntityManyToOne);
					break;
				case "ConsultQuestion":
					this.PerformRelatedEntityRemoval(_consultQuestion, relatedEntity, signalRelatedEntityManyToOne);
					break;
				case "MsgEnvelopes":
					this.PerformRelatedEntityRemoval(_msgEnvelopes, relatedEntity, signalRelatedEntityManyToOne);
					break;
				default:
					break;
			}
		}

		/// <summary> Gets a collection of related entities referenced by this entity which depend on this entity (this entity is the PK side of their FK fields). These entities will have to be persisted after this entity during a recursive save.</summary>
		/// <returns>Collection with 0 or more IEntity objects, referenced by this entity</returns>
		protected override List<IEntity> GetDependingRelatedEntities()
		{
			List<IEntity> toReturn = new List<IEntity>();
			return toReturn;
		}
		
		/// <summary> Gets a collection of related entities referenced by this entity which this entity depends on (this entity is the FK side of their PK fields). These entities will have to be persisted before this entity during a recursive save.</summary>
		/// <returns>Collection with 0 or more IEntity objects, referenced by this entity</returns>
		protected override List<IEntity> GetDependentRelatedEntities()
		{
			List<IEntity> toReturn = new List<IEntity>();
			if(_pacient!=null)
			{
				toReturn.Add(_pacient);
			}
			if(_specialist!=null)
			{
				toReturn.Add(_specialist);
			}
			return toReturn;
		}
		
		/// <summary> Gets a List of all entity collections stored as member variables in this entity. Only 1:n related collections are returned.</summary>
		/// <returns>Collection with 0 or more IEntityCollection objects, referenced by this entity</returns>
		protected override List<IEntityCollection> GetMemberEntityCollections()
		{
			List<IEntityCollection> toReturn = new List<IEntityCollection>();
			toReturn.Add(_appProposal);
			toReturn.Add(_consultQuestion);
			toReturn.Add(_msgEnvelopes);

			return toReturn;
		}


		/// <summary> Fetches the contents of this entity from the persistent storage using the primary key.</summary>
		/// <param name="id">PK value for Consult which data should be fetched into this Consult object</param>
		/// <returns>True if succeeded, false otherwise.</returns>
		public bool FetchUsingPK(System.Int32 id)
		{
			return FetchUsingPK(id, null, null, null);
		}

		/// <summary> Fetches the contents of this entity from the persistent storage using the primary key.</summary>
		/// <param name="id">PK value for Consult which data should be fetched into this Consult object</param>
		/// <param name="prefetchPathToUse">the PrefetchPath which defines the graph of objects to fetch as well</param>
		/// <returns>True if succeeded, false otherwise.</returns>
		public bool FetchUsingPK(System.Int32 id, IPrefetchPath prefetchPathToUse)
		{
			return FetchUsingPK(id, prefetchPathToUse, null, null);
		}

		/// <summary> Fetches the contents of this entity from the persistent storage using the primary key.</summary>
		/// <param name="id">PK value for Consult which data should be fetched into this Consult object</param>
		/// <param name="prefetchPathToUse">the PrefetchPath which defines the graph of objects to fetch as well</param>
		/// <param name="contextToUse">The context to add the entity to if the fetch was succesful. </param>
		/// <returns>True if succeeded, false otherwise.</returns>
		public bool FetchUsingPK(System.Int32 id, IPrefetchPath prefetchPathToUse, Context contextToUse)
		{
			return FetchUsingPK(id, prefetchPathToUse, contextToUse, null);
		}

		/// <summary> Fetches the contents of this entity from the persistent storage using the primary key.</summary>
		/// <param name="id">PK value for Consult which data should be fetched into this Consult object</param>
		/// <param name="prefetchPathToUse">the PrefetchPath which defines the graph of objects to fetch as well</param>
		/// <param name="contextToUse">The context to add the entity to if the fetch was succesful. </param>
		/// <param name="excludedIncludedFields">The list of IEntityField objects which have to be excluded or included for the fetch. 
		/// If null or empty, all fields are fetched (default). If an instance of ExcludeIncludeFieldsList is passed in and its ExcludeContainedFields property
		/// is set to false, the fields contained in excludedIncludedFields are kept in the query, the rest of the fields in the query are excluded.</param>
		/// <returns>True if succeeded, false otherwise.</returns>
		public bool FetchUsingPK(System.Int32 id, IPrefetchPath prefetchPathToUse, Context contextToUse, ExcludeIncludeFieldsList excludedIncludedFields)
		{
			return Fetch(id, prefetchPathToUse, contextToUse, excludedIncludedFields);
		}

		/// <summary> Refetches the Entity from the persistent storage. Refetch is used to re-load an Entity which is marked "Out-of-sync", due to a save action. Refetching an empty Entity has no effect. </summary>
		/// <returns>true if Refetch succeeded, false otherwise</returns>
		public override bool Refetch()
		{
			return Fetch(this.Id, null, null, null);
		}


				
		/// <summary>Gets a list of all the EntityRelation objects the type of this instance has.</summary>
		/// <returns>A list of all the EntityRelation objects the type of this instance has. Hierarchy relations are excluded.</returns>
		protected override List<IEntityRelation> GetAllRelations()
		{
			return new ConsultRelations().GetAllRelations();
		}

		/// <summary> Retrieves all related entities of type 'AppProposalEntity' using a relation of type '1:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <returns>Filled collection with all related entities of type 'AppProposalEntity'</returns>
		public MyHealthOnline.Dal.Generated.CollectionClasses.AppProposalCollection GetMultiAppProposal(bool forceFetch)
		{
			return GetMultiAppProposal(forceFetch, _appProposal.EntityFactoryToUse, null);
		}

		/// <summary> Retrieves all related entities of type 'AppProposalEntity' using a relation of type '1:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <param name="filter">Extra filter to limit the resultset.</param>
		/// <returns>Filled collection with all related entities of type 'AppProposalEntity'</returns>
		public MyHealthOnline.Dal.Generated.CollectionClasses.AppProposalCollection GetMultiAppProposal(bool forceFetch, IPredicateExpression filter)
		{
			return GetMultiAppProposal(forceFetch, _appProposal.EntityFactoryToUse, filter);
		}

		/// <summary> Retrieves all related entities of type 'AppProposalEntity' using a relation of type '1:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <param name="entityFactoryToUse">The entity factory to use for the GetMultiManyToOne() routine.</param>
		/// <returns>Filled collection with all related entities of the type constructed by the passed in entity factory</returns>
		public MyHealthOnline.Dal.Generated.CollectionClasses.AppProposalCollection GetMultiAppProposal(bool forceFetch, IEntityFactory entityFactoryToUse)
		{
			return GetMultiAppProposal(forceFetch, entityFactoryToUse, null);
		}

		/// <summary> Retrieves all related entities of type 'AppProposalEntity' using a relation of type '1:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <param name="entityFactoryToUse">The entity factory to use for the GetMultiManyToOne() routine.</param>
		/// <param name="filter">Extra filter to limit the resultset.</param>
		/// <returns>Filled collection with all related entities of the type constructed by the passed in entity factory</returns>
		public virtual MyHealthOnline.Dal.Generated.CollectionClasses.AppProposalCollection GetMultiAppProposal(bool forceFetch, IEntityFactory entityFactoryToUse, IPredicateExpression filter)
		{
 			if( ( !_alreadyFetchedAppProposal || forceFetch || _alwaysFetchAppProposal) && !this.IsSerializing && !this.IsDeserializing && !this.InDesignMode)
			{
				AddToTransactionIfNecessary(_appProposal);
				_appProposal.SuppressClearInGetMulti=!forceFetch;
				_appProposal.EntityFactoryToUse = entityFactoryToUse;
				_appProposal.GetMultiManyToOne(this, filter);
				_appProposal.SuppressClearInGetMulti=false;
				_alreadyFetchedAppProposal = true;
			}
			return _appProposal;
		}

		/// <summary> Sets the collection parameters for the collection for 'AppProposal'. These settings will be taken into account
		/// when the property AppProposal is requested or GetMultiAppProposal is called.</summary>
		/// <param name="maxNumberOfItemsToReturn"> The maximum number of items to return. When set to 0, this parameter is ignored</param>
		/// <param name="sortClauses">The order by specifications for the sorting of the resultset. When not specified (null), no sorting is applied.</param>
		public virtual void SetCollectionParametersAppProposal(long maxNumberOfItemsToReturn, ISortExpression sortClauses)
		{
			_appProposal.SortClauses=sortClauses;
			_appProposal.MaxNumberOfItemsToReturn=maxNumberOfItemsToReturn;
		}

		/// <summary> Retrieves all related entities of type 'ConsultQuestionEntity' using a relation of type '1:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <returns>Filled collection with all related entities of type 'ConsultQuestionEntity'</returns>
		public MyHealthOnline.Dal.Generated.CollectionClasses.ConsultQuestionCollection GetMultiConsultQuestion(bool forceFetch)
		{
			return GetMultiConsultQuestion(forceFetch, _consultQuestion.EntityFactoryToUse, null);
		}

		/// <summary> Retrieves all related entities of type 'ConsultQuestionEntity' using a relation of type '1:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <param name="filter">Extra filter to limit the resultset.</param>
		/// <returns>Filled collection with all related entities of type 'ConsultQuestionEntity'</returns>
		public MyHealthOnline.Dal.Generated.CollectionClasses.ConsultQuestionCollection GetMultiConsultQuestion(bool forceFetch, IPredicateExpression filter)
		{
			return GetMultiConsultQuestion(forceFetch, _consultQuestion.EntityFactoryToUse, filter);
		}

		/// <summary> Retrieves all related entities of type 'ConsultQuestionEntity' using a relation of type '1:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <param name="entityFactoryToUse">The entity factory to use for the GetMultiManyToOne() routine.</param>
		/// <returns>Filled collection with all related entities of the type constructed by the passed in entity factory</returns>
		public MyHealthOnline.Dal.Generated.CollectionClasses.ConsultQuestionCollection GetMultiConsultQuestion(bool forceFetch, IEntityFactory entityFactoryToUse)
		{
			return GetMultiConsultQuestion(forceFetch, entityFactoryToUse, null);
		}

		/// <summary> Retrieves all related entities of type 'ConsultQuestionEntity' using a relation of type '1:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <param name="entityFactoryToUse">The entity factory to use for the GetMultiManyToOne() routine.</param>
		/// <param name="filter">Extra filter to limit the resultset.</param>
		/// <returns>Filled collection with all related entities of the type constructed by the passed in entity factory</returns>
		public virtual MyHealthOnline.Dal.Generated.CollectionClasses.ConsultQuestionCollection GetMultiConsultQuestion(bool forceFetch, IEntityFactory entityFactoryToUse, IPredicateExpression filter)
		{
 			if( ( !_alreadyFetchedConsultQuestion || forceFetch || _alwaysFetchConsultQuestion) && !this.IsSerializing && !this.IsDeserializing && !this.InDesignMode)
			{
				AddToTransactionIfNecessary(_consultQuestion);
				_consultQuestion.SuppressClearInGetMulti=!forceFetch;
				_consultQuestion.EntityFactoryToUse = entityFactoryToUse;
				_consultQuestion.GetMultiManyToOne(this, filter);
				_consultQuestion.SuppressClearInGetMulti=false;
				_alreadyFetchedConsultQuestion = true;
			}
			return _consultQuestion;
		}

		/// <summary> Sets the collection parameters for the collection for 'ConsultQuestion'. These settings will be taken into account
		/// when the property ConsultQuestion is requested or GetMultiConsultQuestion is called.</summary>
		/// <param name="maxNumberOfItemsToReturn"> The maximum number of items to return. When set to 0, this parameter is ignored</param>
		/// <param name="sortClauses">The order by specifications for the sorting of the resultset. When not specified (null), no sorting is applied.</param>
		public virtual void SetCollectionParametersConsultQuestion(long maxNumberOfItemsToReturn, ISortExpression sortClauses)
		{
			_consultQuestion.SortClauses=sortClauses;
			_consultQuestion.MaxNumberOfItemsToReturn=maxNumberOfItemsToReturn;
		}

		/// <summary> Retrieves all related entities of type 'MessageEntity' using a relation of type '1:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <returns>Filled collection with all related entities of type 'MessageEntity'</returns>
		public MyHealthOnline.Dal.Generated.CollectionClasses.MessageCollection GetMultiMsgEnvelopes(bool forceFetch)
		{
			return GetMultiMsgEnvelopes(forceFetch, _msgEnvelopes.EntityFactoryToUse, null);
		}

		/// <summary> Retrieves all related entities of type 'MessageEntity' using a relation of type '1:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <param name="filter">Extra filter to limit the resultset.</param>
		/// <returns>Filled collection with all related entities of type 'MessageEntity'</returns>
		public MyHealthOnline.Dal.Generated.CollectionClasses.MessageCollection GetMultiMsgEnvelopes(bool forceFetch, IPredicateExpression filter)
		{
			return GetMultiMsgEnvelopes(forceFetch, _msgEnvelopes.EntityFactoryToUse, filter);
		}

		/// <summary> Retrieves all related entities of type 'MessageEntity' using a relation of type '1:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <param name="entityFactoryToUse">The entity factory to use for the GetMultiManyToOne() routine.</param>
		/// <returns>Filled collection with all related entities of the type constructed by the passed in entity factory</returns>
		public MyHealthOnline.Dal.Generated.CollectionClasses.MessageCollection GetMultiMsgEnvelopes(bool forceFetch, IEntityFactory entityFactoryToUse)
		{
			return GetMultiMsgEnvelopes(forceFetch, entityFactoryToUse, null);
		}

		/// <summary> Retrieves all related entities of type 'MessageEntity' using a relation of type '1:n'.</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the collection and will rerun the complete query instead</param>
		/// <param name="entityFactoryToUse">The entity factory to use for the GetMultiManyToOne() routine.</param>
		/// <param name="filter">Extra filter to limit the resultset.</param>
		/// <returns>Filled collection with all related entities of the type constructed by the passed in entity factory</returns>
		public virtual MyHealthOnline.Dal.Generated.CollectionClasses.MessageCollection GetMultiMsgEnvelopes(bool forceFetch, IEntityFactory entityFactoryToUse, IPredicateExpression filter)
		{
 			if( ( !_alreadyFetchedMsgEnvelopes || forceFetch || _alwaysFetchMsgEnvelopes) && !this.IsSerializing && !this.IsDeserializing && !this.InDesignMode)
			{
				AddToTransactionIfNecessary(_msgEnvelopes);
				_msgEnvelopes.SuppressClearInGetMulti=!forceFetch;
				_msgEnvelopes.EntityFactoryToUse = entityFactoryToUse;
				_msgEnvelopes.GetMultiManyToOne(this, filter);
				_msgEnvelopes.SuppressClearInGetMulti=false;
				_alreadyFetchedMsgEnvelopes = true;
			}
			return _msgEnvelopes;
		}

		/// <summary> Sets the collection parameters for the collection for 'MsgEnvelopes'. These settings will be taken into account
		/// when the property MsgEnvelopes is requested or GetMultiMsgEnvelopes is called.</summary>
		/// <param name="maxNumberOfItemsToReturn"> The maximum number of items to return. When set to 0, this parameter is ignored</param>
		/// <param name="sortClauses">The order by specifications for the sorting of the resultset. When not specified (null), no sorting is applied.</param>
		public virtual void SetCollectionParametersMsgEnvelopes(long maxNumberOfItemsToReturn, ISortExpression sortClauses)
		{
			_msgEnvelopes.SortClauses=sortClauses;
			_msgEnvelopes.MaxNumberOfItemsToReturn=maxNumberOfItemsToReturn;
		}

		/// <summary> Retrieves the related entity of type 'PatientEntity', using a relation of type 'n:1'</summary>
		/// <returns>A fetched entity of type 'PatientEntity' which is related to this entity.</returns>
		public PatientEntity GetSinglePacient()
		{
			return GetSinglePacient(false);
		}

		/// <summary> Retrieves the related entity of type 'PatientEntity', using a relation of type 'n:1'</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the currently loaded related entity and will refetch the entity from the persistent storage</param>
		/// <returns>A fetched entity of type 'PatientEntity' which is related to this entity.</returns>
		public virtual PatientEntity GetSinglePacient(bool forceFetch)
		{
			if( ( !_alreadyFetchedPacient || forceFetch || _alwaysFetchPacient) && !this.IsSerializing && !this.IsDeserializing  && !this.InDesignMode)			
			{
				bool performLazyLoading = this.CheckIfLazyLoadingShouldOccur(Relations.PatientEntityUsingPatientId);
				PatientEntity newEntity = new PatientEntity();
				bool fetchResult = false;
				if(performLazyLoading)
				{
					AddToTransactionIfNecessary(newEntity);
					fetchResult = newEntity.FetchUsingPK(this.PatientId.GetValueOrDefault());
				}
				if(fetchResult)
				{
					newEntity = (PatientEntity)GetFromActiveContext(newEntity);
				}
				else
				{
					if(!_pacientReturnsNewIfNotFound)
					{
						RemoveFromTransactionIfNecessary(newEntity);
						newEntity = null;
					}
				}
				this.Pacient = newEntity;
				_alreadyFetchedPacient = fetchResult;
			}
			return _pacient;
		}


		/// <summary> Retrieves the related entity of type 'SpecialistEntity', using a relation of type 'n:1'</summary>
		/// <returns>A fetched entity of type 'SpecialistEntity' which is related to this entity.</returns>
		public SpecialistEntity GetSingleSpecialist()
		{
			return GetSingleSpecialist(false);
		}

		/// <summary> Retrieves the related entity of type 'SpecialistEntity', using a relation of type 'n:1'</summary>
		/// <param name="forceFetch">if true, it will discard any changes currently in the currently loaded related entity and will refetch the entity from the persistent storage</param>
		/// <returns>A fetched entity of type 'SpecialistEntity' which is related to this entity.</returns>
		public virtual SpecialistEntity GetSingleSpecialist(bool forceFetch)
		{
			if( ( !_alreadyFetchedSpecialist || forceFetch || _alwaysFetchSpecialist) && !this.IsSerializing && !this.IsDeserializing  && !this.InDesignMode)			
			{
				bool performLazyLoading = this.CheckIfLazyLoadingShouldOccur(Relations.SpecialistEntityUsingSpecialistId);
				SpecialistEntity newEntity = new SpecialistEntity();
				bool fetchResult = false;
				if(performLazyLoading)
				{
					AddToTransactionIfNecessary(newEntity);
					fetchResult = newEntity.FetchUsingPK(this.SpecialistId);
				}
				if(fetchResult)
				{
					newEntity = (SpecialistEntity)GetFromActiveContext(newEntity);
				}
				else
				{
					if(!_specialistReturnsNewIfNotFound)
					{
						RemoveFromTransactionIfNecessary(newEntity);
						newEntity = null;
					}
				}
				this.Specialist = newEntity;
				_alreadyFetchedSpecialist = fetchResult;
			}
			return _specialist;
		}


		/// <summary>Gets all related data objects, stored by name. The name is the field name mapped onto the relation for that particular data element.</summary>
		/// <returns>Dictionary with per name the related referenced data element, which can be an entity collection or an entity or null</returns>
		protected override Dictionary<string, object> GetRelatedData()
		{
			Dictionary<string, object> toReturn = new Dictionary<string, object>();
			toReturn.Add("Pacient", _pacient);
			toReturn.Add("Specialist", _specialist);
			toReturn.Add("AppProposal", _appProposal);
			toReturn.Add("ConsultQuestion", _consultQuestion);
			toReturn.Add("MsgEnvelopes", _msgEnvelopes);
			return toReturn;
		}
	
		/// <summary> Initializes the class with empty data, as if it is a new Entity.</summary>
		/// <param name="validatorToUse">Validator to use.</param>
		private void InitClassEmpty(IValidator validatorToUse)
		{
			OnInitializing();
			this.Fields = CreateFields();
			this.Validator = validatorToUse;
			InitClassMembers();

			// __LLBLGENPRO_USER_CODE_REGION_START InitClassEmpty
			// __LLBLGENPRO_USER_CODE_REGION_END
			

			OnInitialized();
		}		

		/// <summary> Initializes the the entity and fetches the data related to the entity in this entity.</summary>
		/// <param name="id">PK value for Consult which data should be fetched into this Consult object</param>
		/// <param name="validator">The validator object for this ConsultEntity</param>
		/// <param name="prefetchPathToUse">the PrefetchPath which defines the graph of objects to fetch as well</param>
		private void InitClassFetch(System.Int32 id, IValidator validator, IPrefetchPath prefetchPathToUse)
		{
			OnInitializing();
			this.Validator = validator;
			this.Fields = CreateFields();
			InitClassMembers();	
			Fetch(id, prefetchPathToUse, null, null);

			// __LLBLGENPRO_USER_CODE_REGION_START InitClassFetch
			// __LLBLGENPRO_USER_CODE_REGION_END
			

			OnInitialized();
		}

		/// <summary> Initializes the class members</summary>
		private void InitClassMembers()
		{

			_appProposal = new MyHealthOnline.Dal.Generated.CollectionClasses.AppProposalCollection();
			_appProposal.SetContainingEntityInfo(this, "Consult");

			_consultQuestion = new MyHealthOnline.Dal.Generated.CollectionClasses.ConsultQuestionCollection();
			_consultQuestion.SetContainingEntityInfo(this, "Consult");

			_msgEnvelopes = new MyHealthOnline.Dal.Generated.CollectionClasses.MessageCollection();
			_msgEnvelopes.SetContainingEntityInfo(this, "Consult");
			_pacientReturnsNewIfNotFound = false;
			_specialistReturnsNewIfNotFound = false;
			PerformDependencyInjection();

			// __LLBLGENPRO_USER_CODE_REGION_START InitClassMembers
			// __LLBLGENPRO_USER_CODE_REGION_END
			
			OnInitClassMembersComplete();
		}

		#region Custom Property Hashtable Setup
		/// <summary> Initializes the hashtables for the entity type and entity field custom properties. </summary>
		private static void SetupCustomPropertyHashtables()
		{
			_customProperties = new Dictionary<string, string>();
			_fieldsCustomProperties = new Dictionary<string, Dictionary<string, string>>();
			Dictionary<string, string> fieldHashtable;
			fieldHashtable = new Dictionary<string, string>();
			_fieldsCustomProperties.Add("Conclusion", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();
			_fieldsCustomProperties.Add("ConsultDate", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();
			_fieldsCustomProperties.Add("CreationDate", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();
			_fieldsCustomProperties.Add("DueToBeSent", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();
			_fieldsCustomProperties.Add("Id", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();
			_fieldsCustomProperties.Add("InitialComment", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();
			_fieldsCustomProperties.Add("LatestContact", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();
			_fieldsCustomProperties.Add("LetterStatus", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();
			_fieldsCustomProperties.Add("PatientId", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();
			_fieldsCustomProperties.Add("PersonalNotes", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();
			_fieldsCustomProperties.Add("SpecialistId", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();
			_fieldsCustomProperties.Add("Status", fieldHashtable);
			fieldHashtable = new Dictionary<string, string>();
			_fieldsCustomProperties.Add("Summary", fieldHashtable);
		}
		#endregion

		/// <summary> Removes the sync logic for member _pacient</summary>
		/// <param name="signalRelatedEntity">If set to true, it will call the related entity's UnsetRelatedEntity method</param>
		/// <param name="resetFKFields">if set to true it will also reset the FK fields pointing to the related entity</param>
		private void DesetupSyncPacient(bool signalRelatedEntity, bool resetFKFields)
		{
			this.PerformDesetupSyncRelatedEntity( _pacient, new PropertyChangedEventHandler( OnPacientPropertyChanged ), "Pacient", MyHealthOnline.Dal.Generated.RelationClasses.StaticConsultRelations.PatientEntityUsingPatientIdStatic, true, signalRelatedEntity, "Consult", resetFKFields, new int[] { (int)ConsultFieldIndex.PatientId } );		
			_pacient = null;
		}
		
		/// <summary> setups the sync logic for member _pacient</summary>
		/// <param name="relatedEntity">Instance to set as the related entity of type entityType</param>
		private void SetupSyncPacient(IEntity relatedEntity)
		{
			if(_pacient!=relatedEntity)
			{		
				DesetupSyncPacient(true, true);
				_pacient = (PatientEntity)relatedEntity;
				this.PerformSetupSyncRelatedEntity( _pacient, new PropertyChangedEventHandler( OnPacientPropertyChanged ), "Pacient", MyHealthOnline.Dal.Generated.RelationClasses.StaticConsultRelations.PatientEntityUsingPatientIdStatic, true, ref _alreadyFetchedPacient, new string[] { "Birthday", "PacientName" } );
			}
		}

		/// <summary>Handles property change events of properties in a related entity.</summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void OnPacientPropertyChanged( object sender, PropertyChangedEventArgs e )
		{
			switch( e.PropertyName )
			{
				case "Birthday":
					this.OnPropertyChanged("Birthday");
					break;
				case "Name":
					this.OnPropertyChanged("PacientName");
					break;
				default:
					break;
			}
		}

		/// <summary> Removes the sync logic for member _specialist</summary>
		/// <param name="signalRelatedEntity">If set to true, it will call the related entity's UnsetRelatedEntity method</param>
		/// <param name="resetFKFields">if set to true it will also reset the FK fields pointing to the related entity</param>
		private void DesetupSyncSpecialist(bool signalRelatedEntity, bool resetFKFields)
		{
			this.PerformDesetupSyncRelatedEntity( _specialist, new PropertyChangedEventHandler( OnSpecialistPropertyChanged ), "Specialist", MyHealthOnline.Dal.Generated.RelationClasses.StaticConsultRelations.SpecialistEntityUsingSpecialistIdStatic, true, signalRelatedEntity, "Consults", resetFKFields, new int[] { (int)ConsultFieldIndex.SpecialistId } );		
			_specialist = null;
		}
		
		/// <summary> setups the sync logic for member _specialist</summary>
		/// <param name="relatedEntity">Instance to set as the related entity of type entityType</param>
		private void SetupSyncSpecialist(IEntity relatedEntity)
		{
			if(_specialist!=relatedEntity)
			{		
				DesetupSyncSpecialist(true, true);
				_specialist = (SpecialistEntity)relatedEntity;
				this.PerformSetupSyncRelatedEntity( _specialist, new PropertyChangedEventHandler( OnSpecialistPropertyChanged ), "Specialist", MyHealthOnline.Dal.Generated.RelationClasses.StaticConsultRelations.SpecialistEntityUsingSpecialistIdStatic, true, ref _alreadyFetchedSpecialist, new string[] { "SpecialistName" } );
			}
		}

		/// <summary>Handles property change events of properties in a related entity.</summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void OnSpecialistPropertyChanged( object sender, PropertyChangedEventArgs e )
		{
			switch( e.PropertyName )
			{
				case "Name":
					this.OnPropertyChanged("SpecialistName");
					break;
				default:
					break;
			}
		}

		/// <summary> Fetches the entity from the persistent storage. Fetch simply reads the entity into an EntityFields object. </summary>
		/// <param name="id">PK value for Consult which data should be fetched into this Consult object</param>
		/// <param name="prefetchPathToUse">the PrefetchPath which defines the graph of objects to fetch as well</param>
		/// <param name="contextToUse">The context to add the entity to if the fetch was succesful. </param>
		/// <param name="excludedIncludedFields">The list of IEntityField objects which have to be excluded or included for the fetch. 
		/// If null or empty, all fields are fetched (default). If an instance of ExcludeIncludeFieldsList is passed in and its ExcludeContainedFields property
		/// is set to false, the fields contained in excludedIncludedFields are kept in the query, the rest of the fields in the query are excluded.</param>
		/// <returns>True if succeeded, false otherwise.</returns>
		private bool Fetch(System.Int32 id, IPrefetchPath prefetchPathToUse, Context contextToUse, ExcludeIncludeFieldsList excludedIncludedFields)
		{
			try
			{
				OnFetch();
				this.Fields[(int)ConsultFieldIndex.Id].ForcedCurrentValueWrite(id);
				CreateDAOInstance().FetchExisting(this, this.Transaction, prefetchPathToUse, contextToUse, excludedIncludedFields);
				return (this.Fields.State == EntityState.Fetched);
			}
			finally
			{
				OnFetchComplete();
			}
		}

		/// <summary> Creates the DAO instance for this type</summary>
		/// <returns></returns>
		protected override IDao CreateDAOInstance()
		{
			return DAOFactory.CreateConsultDAO();
		}
		
		/// <summary> Creates the entity factory for this type.</summary>
		/// <returns></returns>
		protected override IEntityFactory CreateEntityFactory()
		{
			return new ConsultEntityFactory();
		}

		#region Class Property Declarations
		/// <summary> The relations object holding all relations of this entity with other entity classes.</summary>
		public  static ConsultRelations Relations
		{
			get	{ return new ConsultRelations(); }
		}
		
		/// <summary> The custom properties for this entity type.</summary>
		/// <remarks>The data returned from this property should be considered read-only: it is not thread safe to alter this data at runtime.</remarks>
		public  static Dictionary<string, string> CustomProperties
		{
			get { return _customProperties;}
		}

		/// <summary> Creates a new PrefetchPathElement object which contains all the information to prefetch the related entities of type 'AppProposal' for this entity.</summary>
		/// <returns>Ready to use IPrefetchPathElement implementation.</returns>
		public static IPrefetchPathElement PrefetchPathAppProposal
		{
			get { return new PrefetchPathElement(new MyHealthOnline.Dal.Generated.CollectionClasses.AppProposalCollection(), (IEntityRelation)GetRelationsForField("AppProposal")[0], (int)MyHealthOnline.Dal.Generated.EntityType.ConsultEntity, (int)MyHealthOnline.Dal.Generated.EntityType.AppProposalEntity, 0, null, null, null, "AppProposal", SD.LLBLGen.Pro.ORMSupportClasses.RelationType.OneToMany); }
		}

		/// <summary> Creates a new PrefetchPathElement object which contains all the information to prefetch the related entities of type 'ConsultQuestion' for this entity.</summary>
		/// <returns>Ready to use IPrefetchPathElement implementation.</returns>
		public static IPrefetchPathElement PrefetchPathConsultQuestion
		{
			get { return new PrefetchPathElement(new MyHealthOnline.Dal.Generated.CollectionClasses.ConsultQuestionCollection(), (IEntityRelation)GetRelationsForField("ConsultQuestion")[0], (int)MyHealthOnline.Dal.Generated.EntityType.ConsultEntity, (int)MyHealthOnline.Dal.Generated.EntityType.ConsultQuestionEntity, 0, null, null, null, "ConsultQuestion", SD.LLBLGen.Pro.ORMSupportClasses.RelationType.OneToMany); }
		}

		/// <summary> Creates a new PrefetchPathElement object which contains all the information to prefetch the related entities of type 'Message' for this entity.</summary>
		/// <returns>Ready to use IPrefetchPathElement implementation.</returns>
		public static IPrefetchPathElement PrefetchPathMsgEnvelopes
		{
			get { return new PrefetchPathElement(new MyHealthOnline.Dal.Generated.CollectionClasses.MessageCollection(), (IEntityRelation)GetRelationsForField("MsgEnvelopes")[0], (int)MyHealthOnline.Dal.Generated.EntityType.ConsultEntity, (int)MyHealthOnline.Dal.Generated.EntityType.MessageEntity, 0, null, null, null, "MsgEnvelopes", SD.LLBLGen.Pro.ORMSupportClasses.RelationType.OneToMany); }
		}

		/// <summary> Creates a new PrefetchPathElement object which contains all the information to prefetch the related entities of type 'Patient'  for this entity.</summary>
		/// <returns>Ready to use IPrefetchPathElement implementation.</returns>
		public static IPrefetchPathElement PrefetchPathPacient
		{
			get	{ return new PrefetchPathElement(new MyHealthOnline.Dal.Generated.CollectionClasses.PatientCollection(), (IEntityRelation)GetRelationsForField("Pacient")[0], (int)MyHealthOnline.Dal.Generated.EntityType.ConsultEntity, (int)MyHealthOnline.Dal.Generated.EntityType.PatientEntity, 0, null, null, null, "Pacient", SD.LLBLGen.Pro.ORMSupportClasses.RelationType.ManyToOne); }
		}

		/// <summary> Creates a new PrefetchPathElement object which contains all the information to prefetch the related entities of type 'Specialist'  for this entity.</summary>
		/// <returns>Ready to use IPrefetchPathElement implementation.</returns>
		public static IPrefetchPathElement PrefetchPathSpecialist
		{
			get	{ return new PrefetchPathElement(new MyHealthOnline.Dal.Generated.CollectionClasses.SpecialistCollection(), (IEntityRelation)GetRelationsForField("Specialist")[0], (int)MyHealthOnline.Dal.Generated.EntityType.ConsultEntity, (int)MyHealthOnline.Dal.Generated.EntityType.SpecialistEntity, 0, null, null, null, "Specialist", SD.LLBLGen.Pro.ORMSupportClasses.RelationType.ManyToOne); }
		}

		/// <summary>Returns the full name for this entity, which is important for the DAO to find back persistence info for this entity.</summary>
		[Browsable(false), XmlIgnore]
		protected override string LLBLGenProEntityName
		{
			get { return "ConsultEntity";}
		}

		/// <summary> The custom properties for the type of this entity instance.</summary>
		/// <remarks>The data returned from this property should be considered read-only: it is not thread safe to alter this data at runtime.</remarks>
		[Browsable(false), XmlIgnore]
		protected override Dictionary<string, string> CustomPropertiesOfType
		{
			get { return CustomProperties;}
		}

		/// <summary> The custom properties for the fields of this entity type. The returned Hashtable contains per fieldname a hashtable of name-value pairs. </summary>
		/// <remarks>The data returned from this property should be considered read-only: it is not thread safe to alter this data at runtime.</remarks>
		public  static Dictionary<string, Dictionary<string, string>> FieldsCustomProperties
		{
			get { return _fieldsCustomProperties;}
		}

		/// <summary> The custom properties for the fields of the type of this entity instance. The returned Hashtable contains per fieldname a hashtable of name-value pairs. </summary>
		/// <remarks>The data returned from this property should be considered read-only: it is not thread safe to alter this data at runtime.</remarks>
		[Browsable(false), XmlIgnore]
		protected override Dictionary<string, Dictionary<string, string>> FieldsCustomPropertiesOfType
		{
			get { return FieldsCustomProperties;}
		}

		/// <summary> The Conclusion property of the Entity Consult<br/><br/></summary>
		/// <remarks>Mapped on  table field: "Consult"."Conclusion"<br/>
		/// Table field type characteristics (type, precision, scale, length): NVarChar, 0, 0, 50<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): true, false, false</remarks>
		public virtual System.String Conclusion
		{
			get { return (System.String)GetValue((int)ConsultFieldIndex.Conclusion, true); }
			set	{ SetValue((int)ConsultFieldIndex.Conclusion, value, true); }
		}

		/// <summary> The ConsultDate property of the Entity Consult<br/><br/></summary>
		/// <remarks>Mapped on  table field: "Consult"."ConsultDate"<br/>
		/// Table field type characteristics (type, precision, scale, length): DateTime, 0, 0, 0<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): true, false, false</remarks>
		public virtual Nullable<System.DateTime> ConsultDate
		{
			get { return (Nullable<System.DateTime>)GetValue((int)ConsultFieldIndex.ConsultDate, false); }
			set	{ SetValue((int)ConsultFieldIndex.ConsultDate, value, true); }
		}

		/// <summary> The CreationDate property of the Entity Consult<br/><br/></summary>
		/// <remarks>Mapped on  table field: "Consult"."CreationDate"<br/>
		/// Table field type characteristics (type, precision, scale, length): DateTime, 0, 0, 0<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): true, false, false</remarks>
		public virtual Nullable<System.DateTime> CreationDate
		{
			get { return (Nullable<System.DateTime>)GetValue((int)ConsultFieldIndex.CreationDate, false); }
			set	{ SetValue((int)ConsultFieldIndex.CreationDate, value, true); }
		}

		/// <summary> The DueToBeSent property of the Entity Consult<br/><br/></summary>
		/// <remarks>Mapped on  table field: "Consult"."DueToBeSent"<br/>
		/// Table field type characteristics (type, precision, scale, length): NVarChar, 0, 0, 10<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): true, false, false</remarks>
		public virtual System.String DueToBeSent
		{
			get { return (System.String)GetValue((int)ConsultFieldIndex.DueToBeSent, true); }
			set	{ SetValue((int)ConsultFieldIndex.DueToBeSent, value, true); }
		}

		/// <summary> The Id property of the Entity Consult<br/><br/></summary>
		/// <remarks>Mapped on  table field: "Consult"."Id"<br/>
		/// Table field type characteristics (type, precision, scale, length): Int, 10, 0, 0<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): false, true, true</remarks>
		public virtual System.Int32 Id
		{
			get { return (System.Int32)GetValue((int)ConsultFieldIndex.Id, true); }
			set	{ SetValue((int)ConsultFieldIndex.Id, value, true); }
		}

		/// <summary> The InitialComment property of the Entity Consult<br/><br/></summary>
		/// <remarks>Mapped on  table field: "Consult"."InitialComment"<br/>
		/// Table field type characteristics (type, precision, scale, length): NVarChar, 0, 0, 255<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): true, false, false</remarks>
		public virtual System.String InitialComment
		{
			get { return (System.String)GetValue((int)ConsultFieldIndex.InitialComment, true); }
			set	{ SetValue((int)ConsultFieldIndex.InitialComment, value, true); }
		}

		/// <summary> The LatestContact property of the Entity Consult<br/><br/></summary>
		/// <remarks>Mapped on  table field: "Consult"."LatestContact"<br/>
		/// Table field type characteristics (type, precision, scale, length): DateTime, 0, 0, 0<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): true, false, false</remarks>
		public virtual Nullable<System.DateTime> LatestContact
		{
			get { return (Nullable<System.DateTime>)GetValue((int)ConsultFieldIndex.LatestContact, false); }
			set	{ SetValue((int)ConsultFieldIndex.LatestContact, value, true); }
		}

		/// <summary> The LetterStatus property of the Entity Consult<br/><br/></summary>
		/// <remarks>Mapped on  table field: "Consult"."LetterStatus"<br/>
		/// Table field type characteristics (type, precision, scale, length): NVarChar, 0, 0, 50<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): true, false, false</remarks>
		public virtual System.String LetterStatus
		{
			get { return (System.String)GetValue((int)ConsultFieldIndex.LetterStatus, true); }
			set	{ SetValue((int)ConsultFieldIndex.LetterStatus, value, true); }
		}

		/// <summary> The PatientId property of the Entity Consult<br/><br/></summary>
		/// <remarks>Mapped on  table field: "Consult"."PatientId"<br/>
		/// Table field type characteristics (type, precision, scale, length): Int, 10, 0, 0<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): true, false, false</remarks>
		public virtual Nullable<System.Int32> PatientId
		{
			get { return (Nullable<System.Int32>)GetValue((int)ConsultFieldIndex.PatientId, false); }
			set	{ SetValue((int)ConsultFieldIndex.PatientId, value, true); }
		}

		/// <summary> The PersonalNotes property of the Entity Consult<br/><br/></summary>
		/// <remarks>Mapped on  table field: "Consult"."PersonalNotes"<br/>
		/// Table field type characteristics (type, precision, scale, length): NVarChar, 0, 0, 1024<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): true, false, false</remarks>
		public virtual System.String PersonalNotes
		{
			get { return (System.String)GetValue((int)ConsultFieldIndex.PersonalNotes, true); }
			set	{ SetValue((int)ConsultFieldIndex.PersonalNotes, value, true); }
		}

		/// <summary> The SpecialistId property of the Entity Consult<br/><br/></summary>
		/// <remarks>Mapped on  table field: "Consult"."SpecialistId"<br/>
		/// Table field type characteristics (type, precision, scale, length): NVarChar, 0, 0, 50<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): true, false, false</remarks>
		public virtual System.String SpecialistId
		{
			get { return (System.String)GetValue((int)ConsultFieldIndex.SpecialistId, true); }
			set	{ SetValue((int)ConsultFieldIndex.SpecialistId, value, true); }
		}

		/// <summary> The Status property of the Entity Consult<br/><br/></summary>
		/// <remarks>Mapped on  table field: "Consult"."Status"<br/>
		/// Table field type characteristics (type, precision, scale, length): NVarChar, 0, 0, 255<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): true, false, false</remarks>
		public virtual System.String Status
		{
			get { return (System.String)GetValue((int)ConsultFieldIndex.Status, true); }
			set	{ SetValue((int)ConsultFieldIndex.Status, value, true); }
		}

		/// <summary> The Summary property of the Entity Consult<br/><br/></summary>
		/// <remarks>Mapped on  table field: "Consult"."Summary"<br/>
		/// Table field type characteristics (type, precision, scale, length): NVarChar, 0, 0, 1024<br/>
		/// Table field behavior characteristics (is nullable, is PK, is identity): true, false, false</remarks>
		public virtual System.String Summary
		{
			get { return (System.String)GetValue((int)ConsultFieldIndex.Summary, true); }
			set	{ SetValue((int)ConsultFieldIndex.Summary, value, true); }
		}

		/// <summary> Retrieves all related entities of type 'AppProposalEntity' using a relation of type '1:n'.<br/><br/>
		/// </summary>
		/// <remarks>This property is added for databinding conveniance, however it is recommeded to use the method 'GetMultiAppProposal()', because 
		/// this property is rather expensive and a method tells the user to cache the result when it has to be used more than once in the same scope.</remarks>
		public virtual MyHealthOnline.Dal.Generated.CollectionClasses.AppProposalCollection AppProposal
		{
			get	{ return GetMultiAppProposal(false); }
		}

		/// <summary> Gets / sets the lazy loading flag for AppProposal. When set to true, AppProposal is always refetched from the 
		/// persistent storage. When set to false, the data is only fetched the first time AppProposal is accessed. You can always execute/ a forced fetch by calling GetMultiAppProposal(true).</summary>
		[Browsable(false)]
		public bool AlwaysFetchAppProposal
		{
			get	{ return _alwaysFetchAppProposal; }
			set	{ _alwaysFetchAppProposal = value; }	
		}		
				
		/// <summary>Gets / Sets the lazy loading flag if the property AppProposal already has been fetched. Setting this property to false when AppProposal has been fetched
		/// will clear the AppProposal collection well. Setting this property to true while AppProposal hasn't been fetched disables lazy loading for AppProposal</summary>
		[Browsable(false)]
		public bool AlreadyFetchedAppProposal
		{
			get { return _alreadyFetchedAppProposal;}
			set 
			{
				if(_alreadyFetchedAppProposal && !value && (_appProposal != null))
				{
					_appProposal.Clear();
				}
				_alreadyFetchedAppProposal = value;
			}
		}
		/// <summary> Retrieves all related entities of type 'ConsultQuestionEntity' using a relation of type '1:n'.<br/><br/>
		/// </summary>
		/// <remarks>This property is added for databinding conveniance, however it is recommeded to use the method 'GetMultiConsultQuestion()', because 
		/// this property is rather expensive and a method tells the user to cache the result when it has to be used more than once in the same scope.</remarks>
		public virtual MyHealthOnline.Dal.Generated.CollectionClasses.ConsultQuestionCollection ConsultQuestion
		{
			get	{ return GetMultiConsultQuestion(false); }
		}

		/// <summary> Gets / sets the lazy loading flag for ConsultQuestion. When set to true, ConsultQuestion is always refetched from the 
		/// persistent storage. When set to false, the data is only fetched the first time ConsultQuestion is accessed. You can always execute/ a forced fetch by calling GetMultiConsultQuestion(true).</summary>
		[Browsable(false)]
		public bool AlwaysFetchConsultQuestion
		{
			get	{ return _alwaysFetchConsultQuestion; }
			set	{ _alwaysFetchConsultQuestion = value; }	
		}		
				
		/// <summary>Gets / Sets the lazy loading flag if the property ConsultQuestion already has been fetched. Setting this property to false when ConsultQuestion has been fetched
		/// will clear the ConsultQuestion collection well. Setting this property to true while ConsultQuestion hasn't been fetched disables lazy loading for ConsultQuestion</summary>
		[Browsable(false)]
		public bool AlreadyFetchedConsultQuestion
		{
			get { return _alreadyFetchedConsultQuestion;}
			set 
			{
				if(_alreadyFetchedConsultQuestion && !value && (_consultQuestion != null))
				{
					_consultQuestion.Clear();
				}
				_alreadyFetchedConsultQuestion = value;
			}
		}
		/// <summary> Retrieves all related entities of type 'MessageEntity' using a relation of type '1:n'.<br/><br/>
		/// </summary>
		/// <remarks>This property is added for databinding conveniance, however it is recommeded to use the method 'GetMultiMsgEnvelopes()', because 
		/// this property is rather expensive and a method tells the user to cache the result when it has to be used more than once in the same scope.</remarks>
		public virtual MyHealthOnline.Dal.Generated.CollectionClasses.MessageCollection MsgEnvelopes
		{
			get	{ return GetMultiMsgEnvelopes(false); }
		}

		/// <summary> Gets / sets the lazy loading flag for MsgEnvelopes. When set to true, MsgEnvelopes is always refetched from the 
		/// persistent storage. When set to false, the data is only fetched the first time MsgEnvelopes is accessed. You can always execute/ a forced fetch by calling GetMultiMsgEnvelopes(true).</summary>
		[Browsable(false)]
		public bool AlwaysFetchMsgEnvelopes
		{
			get	{ return _alwaysFetchMsgEnvelopes; }
			set	{ _alwaysFetchMsgEnvelopes = value; }	
		}		
				
		/// <summary>Gets / Sets the lazy loading flag if the property MsgEnvelopes already has been fetched. Setting this property to false when MsgEnvelopes has been fetched
		/// will clear the MsgEnvelopes collection well. Setting this property to true while MsgEnvelopes hasn't been fetched disables lazy loading for MsgEnvelopes</summary>
		[Browsable(false)]
		public bool AlreadyFetchedMsgEnvelopes
		{
			get { return _alreadyFetchedMsgEnvelopes;}
			set 
			{
				if(_alreadyFetchedMsgEnvelopes && !value && (_msgEnvelopes != null))
				{
					_msgEnvelopes.Clear();
				}
				_alreadyFetchedMsgEnvelopes = value;
			}
		}

		/// <summary> Gets / sets related entity of type 'PatientEntity'. This property is not visible in databound grids.
		/// Setting this property to a new object will make the load-on-demand feature to stop fetching data from the database, until you set this
		/// property to null. Setting this property to an entity will make sure that FK-PK relations are synchronized when appropriate.<br/><br/>
		/// </summary>
		/// <remarks>This property is added for conveniance, however it is recommeded to use the method 'GetSinglePacient()', because 
		/// this property is rather expensive and a method tells the user to cache the result when it has to be used more than once in the
		/// same scope. The property is marked non-browsable to make it hidden in bound controls, f.e. datagrids.</remarks>
		[Browsable(false)]
		public virtual PatientEntity Pacient
		{
			get	{ return GetSinglePacient(false); }
			set 
			{ 
				if(this.IsDeserializing)
				{
					SetupSyncPacient(value);
				}
				else
				{
					SetSingleRelatedEntityNavigator(value, "Consult", "Pacient", _pacient, true); 
				}
			}
		}

		/// <summary> Gets / sets the lazy loading flag for Pacient. When set to true, Pacient is always refetched from the 
		/// persistent storage. When set to false, the data is only fetched the first time Pacient is accessed. You can always execute a forced fetch by calling GetSinglePacient(true).</summary>
		[Browsable(false)]
		public bool AlwaysFetchPacient
		{
			get	{ return _alwaysFetchPacient; }
			set	{ _alwaysFetchPacient = value; }	
		}
				
		/// <summary>Gets / Sets the lazy loading flag if the property Pacient already has been fetched. Setting this property to false when Pacient has been fetched
		/// will set Pacient to null as well. Setting this property to true while Pacient hasn't been fetched disables lazy loading for Pacient</summary>
		[Browsable(false)]
		public bool AlreadyFetchedPacient
		{
			get { return _alreadyFetchedPacient;}
			set 
			{
				if(_alreadyFetchedPacient && !value)
				{
					this.Pacient = null;
				}
				_alreadyFetchedPacient = value;
			}
		}

		/// <summary> Gets / sets the flag for what to do if the related entity available through the property Pacient is not found
		/// in the database. When set to true, Pacient will return a new entity instance if the related entity is not found, otherwise 
		/// null be returned if the related entity is not found. Default: false.</summary>
		[Browsable(false)]
		public bool PacientReturnsNewIfNotFound
		{
			get	{ return _pacientReturnsNewIfNotFound; }
			set { _pacientReturnsNewIfNotFound = value; }	
		}

		/// <summary> Gets / sets related entity of type 'SpecialistEntity'. This property is not visible in databound grids.
		/// Setting this property to a new object will make the load-on-demand feature to stop fetching data from the database, until you set this
		/// property to null. Setting this property to an entity will make sure that FK-PK relations are synchronized when appropriate.<br/><br/>
		/// </summary>
		/// <remarks>This property is added for conveniance, however it is recommeded to use the method 'GetSingleSpecialist()', because 
		/// this property is rather expensive and a method tells the user to cache the result when it has to be used more than once in the
		/// same scope. The property is marked non-browsable to make it hidden in bound controls, f.e. datagrids.</remarks>
		[Browsable(false)]
		public virtual SpecialistEntity Specialist
		{
			get	{ return GetSingleSpecialist(false); }
			set 
			{ 
				if(this.IsDeserializing)
				{
					SetupSyncSpecialist(value);
				}
				else
				{
					SetSingleRelatedEntityNavigator(value, "Consults", "Specialist", _specialist, true); 
				}
			}
		}

		/// <summary> Gets / sets the lazy loading flag for Specialist. When set to true, Specialist is always refetched from the 
		/// persistent storage. When set to false, the data is only fetched the first time Specialist is accessed. You can always execute a forced fetch by calling GetSingleSpecialist(true).</summary>
		[Browsable(false)]
		public bool AlwaysFetchSpecialist
		{
			get	{ return _alwaysFetchSpecialist; }
			set	{ _alwaysFetchSpecialist = value; }	
		}
				
		/// <summary>Gets / Sets the lazy loading flag if the property Specialist already has been fetched. Setting this property to false when Specialist has been fetched
		/// will set Specialist to null as well. Setting this property to true while Specialist hasn't been fetched disables lazy loading for Specialist</summary>
		[Browsable(false)]
		public bool AlreadyFetchedSpecialist
		{
			get { return _alreadyFetchedSpecialist;}
			set 
			{
				if(_alreadyFetchedSpecialist && !value)
				{
					this.Specialist = null;
				}
				_alreadyFetchedSpecialist = value;
			}
		}

		/// <summary> Gets / sets the flag for what to do if the related entity available through the property Specialist is not found
		/// in the database. When set to true, Specialist will return a new entity instance if the related entity is not found, otherwise 
		/// null be returned if the related entity is not found. Default: false.</summary>
		[Browsable(false)]
		public bool SpecialistReturnsNewIfNotFound
		{
			get	{ return _specialistReturnsNewIfNotFound; }
			set { _specialistReturnsNewIfNotFound = value; }	
		}

 
		/// <summary> Gets / Sets the value of the related field this.Pacient.Birthday.<br/><br/></summary>
		public virtual Nullable<System.DateTime> Birthday
		{
			get
			{
				PatientEntity relatedEntity = this.Pacient;
				return relatedEntity==null ? (Nullable<System.DateTime>)TypeDefaultValue.GetDefaultValue(typeof(Nullable<System.DateTime>)) : relatedEntity.Birthday;
			}
			set
			{
				PatientEntity relatedEntity = this.Pacient;
				if(relatedEntity!=null)
				{
					relatedEntity.Birthday = value;
				}				
			}
		}
 
		/// <summary> Gets / Sets the value of the related field this.Pacient.Name.<br/><br/></summary>
		public virtual System.String PacientName
		{
			get
			{
				PatientEntity relatedEntity = this.Pacient;
				return relatedEntity==null ? (System.String)TypeDefaultValue.GetDefaultValue(typeof(System.String)) : relatedEntity.Name;
			}
			set
			{
				PatientEntity relatedEntity = this.Pacient;
				if(relatedEntity!=null)
				{
					relatedEntity.Name = value;
				}				
			}
		}
 
		/// <summary> Gets / Sets the value of the related field this.Specialist.Name.<br/><br/></summary>
		public virtual System.String SpecialistName
		{
			get
			{
				SpecialistEntity relatedEntity = this.Specialist;
				return relatedEntity==null ? (System.String)TypeDefaultValue.GetDefaultValue(typeof(System.String)) : relatedEntity.Name;
			}
			set
			{
				SpecialistEntity relatedEntity = this.Specialist;
				if(relatedEntity!=null)
				{
					relatedEntity.Name = value;
				}				
			}
		}

		/// <summary> Gets or sets a value indicating whether this entity is a subtype</summary>
		protected override bool LLBLGenProIsSubType
		{
			get { return false;}
		}

		/// <summary> Gets the type of the hierarchy this entity is in. </summary>
		[System.ComponentModel.Browsable(false), XmlIgnore]
		protected override InheritanceHierarchyType LLBLGenProIsInHierarchyOfType
		{
			get { return InheritanceHierarchyType.None;}
		}
		
		/// <summary>Returns the MyHealthOnline.Dal.Generated.EntityType enum value for this entity.</summary>
		[Browsable(false), XmlIgnore]
		protected override int LLBLGenProEntityTypeValue 
		{ 
			get { return (int)MyHealthOnline.Dal.Generated.EntityType.ConsultEntity; }
		}

		#endregion


		#region Custom Entity code
		
		// __LLBLGENPRO_USER_CODE_REGION_START CustomEntityCode
		// __LLBLGENPRO_USER_CODE_REGION_END
		
		#endregion

		#region Included code

		#endregion
	}
}
